﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">
    $(function() {
        var options = {
            slide_all: false
        };
        $("#worktable_main").selfAccordion(options);
        //        var obj=$("#worktable_main .table_style");
        //        $.each(obj,function(i,val){
        //            $(obj.eq(i)).tablesorter(); 
        //        });
        tableSelectOrder("#worktable_main .table_style");
    });

    function doGetTaskFlowChart(uniqueId) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoGetTaskFlowChart",
            data: { "uniqueId": uniqueId },
            success: function(data) {
                addtab('2-5', '查看流程');
                var workarea = $("#workarea-2-5").html("<div id='procedure'></div>");
                var procedure = $(workarea).children("#procedure");
                var drag = $.fn.Procedure({ renderTo: procedure, inititedata: data });
            }
        });
    }

    function dowfcancel(task_id) {
        if (!confirm("确认要废弃该单据吗？"))
            return false;

        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoWFCancel",
            data: { task_id: task_id },
            success: function(restag) {
                alert(restag.msg);
                $('#menu_worktable').trigger('click');
            }
        });
    }

    // 审批流程
    function workflowapproval(uniqueid, task_id, ptask_id) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/WFProcess",
            data: { "uniqueid": uniqueid, "task_id": task_id, "ptask_id": ptask_id },
            success: function(data) {
                addtab('2-2-examine', '审批');
                $("#workarea-2-2-examine").html(data);
            }
        })
    }

    // 代为审批流程
    function workflowhelperapproval(uniqueid, task_id, ptask_id, str_id) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/WFProcess",
            data: { "uniqueid": uniqueid, "task_id": task_id, "ptask_id": ptask_id, "str_id": str_id },
            success: function(data) {
                addtab('2-2-examine', '委托审批');
                $("#workarea-2-2-examine").html(data);
            }
        })
    }
</script>

<div id="worktable_main" style="padding-top: 35px;">
    <div id="worktable_curtasklist">
        <h3>
            <a style="float: left;" href="#">我的审批</a> <a class="a_more" title="更多" onclick="$('#menu_wfcurtasklist').trigger('click');"
                style="text-align: right; width: 40px; float: right; margin-top: 5px; height: 12px"
                href="javascript:void(0)"></a>
        </h3>
        <div>
            <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th class="th_long">
                            审批单名称
                        </th>
                        <th class="th_short">
                            申请人
                        </th>
                        <th class="th_middle">
                            部门
                        </th>
                        <th class="th_middle">
                            流程状态
                        </th>
                        <th class="th_middle">
                            审批到达时间
                        </th>
                        <th>
                            备注
                        </th>
                        <th class="th_middle">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        System.Data.DataTable dt_wfworking = ViewData["dt_wfworking"] as System.Data.DataTable;
                        if (dt_wfworking != null && dt_wfworking.Rows.Count != 0)
                        {
                            for (int i = 0; i < (dt_wfworking.Rows.Count > 10 ? 10 : dt_wfworking.Rows.Count); i++)
                            {
                    %>
                    <tr>
                        <td>
                            <%=dt_wfworking.Rows[i]["流程名称"]%>
                        </td>
                        <td>
                            <%=dt_wfworking.Rows[i]["发起人"]%>
                        </td>
                        <td>
                            <%=dt_wfworking.Rows[i]["部门"]%>
                        </td>
                        <td>
                            <%=dt_wfworking.Rows[i]["任务名称"]%>
                        </td>
                        <td>
                            <%=DateTime.Parse(dt_wfworking.Rows[i]["开始时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                        </td>
                        <td title='<%=dt_wfworking.Rows[i]["备注"].ToString() %>'>
                            <%=dt_wfworking.Rows[i]["备注"].ToString().Length > 25 ? dt_wfworking.Rows[i]["备注"].ToString().Remove(25) : dt_wfworking.Rows[i]["备注"].ToString()%>
                        </td>
                        <td>
                            <a class="approve" onclick="workflowapproval('<%=dt_wfworking.Rows[i]["实例标识"] %>','<%=dt_wfworking.Rows[i]["任务编码"] %>','<%=dt_wfworking.Rows[i]["父级编码"] %>')">
                                审批</a>
                            <%if (dt_wfworking.Rows[i]["发起人编码"].ToString() == ViewData["user_id"].ToString())
                              { %>
                            <a class="btn_delete" title="废弃" onclick='dowfcancel(<%=dt_wfworking.Rows[i]["任务编码"].ToString() %>)'>
                                废弃</a>
                            <%} %>
                        </td>
                    </tr>
                    <%
                        }
                        }
                        else
                        { %>
                    <tr>
                        <td colspan="0" style="text-align: center;">
                            当前无数据！
                        </td>
                    </tr>
                    <%} %>
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <h3>
            <a style="float: left;" href="#">历史申请</a> <a class="a_more" title="更多" onclick="$('#menu_wfstartlist').trigger('click');"
                style="text-align: right; width: 40px; float: right; margin-top: 5px; height: 12px"
                href="javascript:void(0)"></a>
        </h3>
        <div>
            <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th class="th_long">
                            申请单名称
                        </th>
                        <th class="th_short">
                            申请人
                        </th>
                        <th class="th_middle">
                            流程状态
                        </th>
                        <th class="th_middle">
                            申请时间
                        </th>
                        <th>
                            备注
                        </th>
                        <th class="th_long">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        System.Data.DataTable dt_wfstart = ViewData["dt_wfstart"] as System.Data.DataTable;
                        if (dt_wfstart != null && dt_wfstart.Rows.Count > 0)
                        {
                            for (int i = 0; i < (dt_wfstart.Rows.Count > 10 ? 10 : dt_wfstart.Rows.Count); i++)
                            {
                    %>
                    <tr>
                        <td>
                            <%=dt_wfstart.Rows[i]["名称"]%>
                        </td>
                        <td>
                            <%=dt_wfstart.Rows[i]["发起人"]%>
                        </td>
                        <td>
                            <%=dt_wfstart.Rows[i]["结果"].ToString()=="未完成"?"进行中":dt_wfstart.Rows[i]["结果"].ToString()%>
                        </td>
                        <td>
                            <%=DateTime.Parse(dt_wfstart.Rows[i]["发起日期"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                        </td>
                        <td title='<%=dt_wfstart.Rows[i]["备注"].ToString() %>'>
                            <%=dt_wfstart.Rows[i]["备注"].ToString().Length > 25 ? dt_wfstart.Rows[i]["备注"].ToString().Remove(25) : dt_wfstart.Rows[i]["备注"].ToString()%>
                        </td>
                        <td>
                            <%--<%=Ajax.ActionLink("查看", "WFTaskDetails","WorkFlow",
                                    new { uniqueId = dt_wfstart.Rows[i]["唯一标识"] },
                                                                                            new AjaxOptions { UpdateTargetId = "workarea-2-5", OnSuccess = "addtab('2-5','审批流程')" }, new { @class = "btn_detail" })%>--%>
                            <a class="btn_detail" onclick="openWin('/WorkFlow/WFShow?task_id=<%=dt_wfstart.Rows[i]["任务编码"]%>',100,100,800,1000)">
                                申请内容</a> <a class="btn_detail" onclick="doGetTaskFlowChart('<%=dt_wfstart.Rows[i]["唯一标识"] %>')">
                                    审批状态</a>
                        </td>
                    </tr>
                    <%
                        }
                        }
                        else
                        { %>
                    <tr>
                        <td colspan="0" style="text-align: center;">
                            当前无数据！
                        </td>
                    </tr>
                    <%} %>
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <h3>
            <a style="float: left;" href="#">历史审批</a> <a class="a_more" title="更多" onclick="$('#menu_wffinishlist').trigger('click');"
                style="text-align: right; width: 40px; float: right; margin-top: 5px; height: 12px"
                href="javascript:void(0)"></a>
        </h3>
        <div>
            <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th class="th_long">
                            申请单名称
                        </th>
                        <th class="th_short">
                            申请人
                        </th>
                        <th class="th_middle">
                            部门
                        </th>
                        <th class="th_middle">
                            流程状态
                        </th>
                        <th class="th_middle">
                            审批到达时间
                        </th>
                        <th class="th_middle">
                            审批完成时间
                        </th>
                        <th>
                        </th>
                        <th class="th_middle">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        System.Data.DataTable dt_wfworked = ViewData["dt_wfworked"] as System.Data.DataTable;
                        if (dt_wfworked != null && dt_wfworked.Rows.Count > 0)
                        {
                            for (int i = 0; i < (dt_wfworked.Rows.Count > 10 ? 10 : dt_wfworked.Rows.Count); i++)
                            {
                    %>
                    <tr>
                        <td>
                            <%=dt_wfworked.Rows[i]["流程名称"]%>
                        </td>
                        <td>
                            <%=dt_wfworked.Rows[i]["发起人"]%>
                        </td>
                        <td>
                            <%=dt_wfworked.Rows[i]["部门2"]%>
                        </td>
                        <td>
                            <%=dt_wfworked.Rows[i]["任务名称"]%>
                        </td>
                        <td>
                            <%=DateTime.Parse(dt_wfworked.Rows[i]["开始时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                        </td>
                        <td>
                            <%=DateTime.Parse(dt_wfworked.Rows[i]["完成时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                        </td>
                        <td>
                        </td>
                        <%--<td title='<%=dt_wfworked.Rows[i]["备注"].ToString() %>'>
                            <%=dt_wfworked.Rows[i]["备注"].ToString().Length > 25? dt_wfworked.Rows[i]["备注"].ToString().Remove(25) : dt_wfworked.Rows[i]["备注"].ToString()%>
                        </td>--%>
                        <td>
                            <%--  <%=Ajax.ActionLink("查看", "WFTaskDetails", "WorkFlow",
                        new { uniqueId = dt_wfworked.Rows[i]["实例标识"] },
                                                            new AjaxOptions { UpdateTargetId = "workarea-1-1-2-check", OnSuccess = "addtab('1-1-2-check','审批查看')" }, new { @class = "btn_detail" })%>--%>
                            <a class="btn_detail" onclick="doGetTaskFlowChart('<%=dt_wfworked.Rows[i]["实例标识"] %>')">
                                审批状态</a>
                        </td>
                    </tr>
                    <%
                        }
                        }
                        else
                        { %>
                    <tr>
                        <td colspan="0" style="text-align: center;">
                            当前无数据！
                        </td>
                    </tr>
                    <%} %>
                </tbody>
            </table>
        </div>
    </div>
    <div>
        <h3>
            <a style="float: left;" href="#">委托审批</a> <a class="a_more" title="更多" onclick="$('#menu_wfcurdelegtasklist').trigger('click');"
                style="text-align: right; width: 40px; float: right; margin-top: 5px; height: 12px"
                href="javascript:void(0)"></a>
        </h3>
        <div>
            <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
                <thead>
                    <tr>
                        <th class="th_long">
                            审批单名称
                        </th>
                        <th class="th_short">
                            申请人
                        </th>
                        <th class="th_middle">
                            部门
                        </th>
                        <th class="th_middle">
                            委托人
                        </th>
                        <th class="th_middle">
                            部门
                        </th>
                        <th class="th_middle">
                            委托到达时间
                        </th>
                        <th>
                        </th>
                        <th class="th_middle">
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <%
                        System.Data.DataTable dt_delegtask = ViewData["dt_delegtask"] as System.Data.DataTable;
                        if (dt_delegtask != null && dt_delegtask.Rows.Count > 0)
                        {
                            for (int i = 0; i < (dt_delegtask.Rows.Count > 10 ? 10 : dt_delegtask.Rows.Count); i++)
                            {
                    %>
                    <tr>
                        <td>
                            <%=dt_delegtask.Rows[i]["流程名称"]%>
                        </td>
                        <td>
                            <%=dt_delegtask.Rows[i]["发起人"]%>
                        </td>
                        <td>
                            <%=dt_delegtask.Rows[i]["部门1"]%>
                        </td>
                        <td>
                            <%=dt_delegtask.Rows[i]["委托人"]%>
                        </td>
                        <td>
                            <%=dt_delegtask.Rows[i]["部门2"]%>
                        </td>
                        <td>
                            <%=DateTime.Parse(dt_delegtask.Rows[i]["开始时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                        </td>
                        <td>
                        </td>
                        <td>
                            <a class="approve" onclick="workflowhelperapproval('<%= dt_delegtask.Rows[i]["实例标识"] %>',
                                '<%=dt_delegtask.Rows[i]["任务编码"] %>','<%=dt_delegtask.Rows[i]["父级编码"] %>',
                                '<%=ViewData["user_id"] %>')">代为审批</a>
                        </td>
                    </tr>
                    <%
                        }
                        }
                        else
                        { %>
                    <tr>
                        <td colspan="0" style="text-align: center;">
                            当前无数据！
                        </td>
                    </tr>
                    <%} %>
                </tbody>
            </table>
        </div>
    </div>
</div>
